package xaj.scc.ast;

import polyglot.ast.Node;
import polyglot.ext.jl.ast.Node_c;
import polyglot.util.CodeWriter;
import polyglot.util.Position;
import polyglot.visit.NodeVisitor;
import polyglot.visit.PrettyPrinter;

public class OptionalFactor_c extends Node_c implements OptionalFactor {

	private Factor factor;
	
	public OptionalFactor_c(Position pos, Factor factor) {
		super(pos);
		this.factor = factor;
	}

	public Factor getFactor() {
		return factor;
	}

	public OptionalFactor setFactor(Factor factor) {
		OptionalFactor_c n = (OptionalFactor_c) copy();
		n.factor= factor;
		return n;
	}

	protected OptionalFactor_c reconstruct(Factor f) {
		if(factor != f) {
			OptionalFactor_c n = (OptionalFactor_c) copy();
			n.factor = f;
			return n;
		}
		return this;
	}
	
	public Node visitChildren(NodeVisitor v) {
		Factor factor = (Factor) this.factor.visit(v);
		return reconstruct(factor);
	}
	
	public void prettyPrint(CodeWriter w, PrettyPrinter tr) {
		w.write("[");
		factor.prettyPrint(w, tr);
		w.write("]");
	}

	@Override
	public void accept(Visitor v) {
		v.visitOptionalFactor(this);
		
	}
}
